home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / AmigaTalk / general / Semaphore.st < prev    next >
Text File  |  2000-02-16  |  800b  |  32 lines

  1. "-----------------------------------------------------------"
  2. " Semaphore Class is NOT the same as Amiga Exec Semaphores. "
  3. "-----------------------------------------------------------"
  4.  
  5. Class Semaphore :List
  6. ! excessSignals !
  7. [  
  8.    new
  9.       excessSignals <- 0
  10. |  
  11.    new: aNumber
  12.       excessSignals <- aNumber
  13. |  
  14.    signal
  15.       <primitive 148>.   "start atomic action"
  16.  
  17.       (self isEmpty)
  18.          ifTrue:  [excessSignals <- excessSignals + 1]
  19.          ifFalse: [self removeFirst unblock].
  20.  
  21.       <primitive 149>    "end atomic action"
  22. |  
  23.    wait
  24.       <primitive 148>.   "start atomic actions"
  25.  
  26.       (excessSignals = 0)
  27.          ifTrue: [self addLast: selfProcess.  selfProcess block]
  28.         ifFalse: [excessSignals <- excessSignals - 1].
  29.  
  30.       <primitive 149>    "end atomic actions"
  31. ]
  32.